<?php
declare (strict_types = 1);

namespace app\controller;




class Swiftmailer  extends Common
{
    public function __construct()
    {
        parent::__construct();
    }

    public function index()
    {


        $transport = (new \Swift_SmtpTransport('ssl:smtp.163.com', 465)) // 邮箱服务器
        //$transport = (new \Swift_SmtpTransport('smtp.163.com', 25)) // 邮箱服务器
        ->setUsername('k571031767@163.com')  // 邮箱用户名
        ->setPassword('hanyu12345')   // 邮箱密码，有的邮件服务器是授权码
        ;

        $mailer = new \Swift_Mailer($transport);


        $message = (new \Swift_Message('Wonderful Subject')) // 邮件标题
        ->setFrom(['john@doe.com' => 'John Doe']) // 发送者
        ->setTo(['receiver@domain.org', 'other@domain.org' => 'A name']) //发送对象，数组形式支持多个
        ->setBody('Here is the message itself') //邮件内容
        ;

        //https://www.helloweba.net/php/457.html  教程地址

        $result = $mailer->send($message);
        
    }
}
